﻿using AutoMapper;
using ManagementApi.Models.Template;
using Modules;
using Modules.System.Attachment;
using PmSoft;

namespace ManagementApi.Models.SysAttachment
{
    public class SysAttachmentDto
    {
        /// <summary>
        /// 附件ID
        ///</summary>
        public string Id { get; set; }

        /// <summary>
        /// 文件名称
        ///</summary>
        public string Name { get; set; }

        /// <summary>
        /// 桶名称
        /// </summary>
        public string BucketName { get; set; }

        /// <summary>
        /// 对象名称，包含路径
        /// </summary>
        public string ObjectFilePath { get; set; }

        /// <summary>
        /// 友好的文件名称
        ///</summary>
        public string FriendlyName { get; set; }

        /// <summary>
        /// 媒体类型
        ///</summary>
        public MediaType MediaType { get; set; }

        /// <summary>
        /// 附件MIME类型
        ///</summary>
        public string ContentType { get; set; }

        /// <summary>
        /// 上传者IP
        ///</summary>
        public string Ip { get; set; }
    }

    public static partial class SysAttachmentExceptions
    {
        public static SysAttachmentDto AsDto(this AttachmentInfo entity)
        {
            var mapper = ServiceAccessor.GetService<IMapper>();
            return mapper.Map<SysAttachmentDto>(entity);
        }

        public static IEnumerable<SysAttachmentDto> AsDtos(this IEnumerable<AttachmentInfo> sysTemplates)
        {
            var mapper = ServiceAccessor.GetService<IMapper>();
            return mapper.Map<IEnumerable<SysAttachmentDto>>(sysTemplates);
        }
    }
}